﻿namespace Example.Creational.Builder
{
    using System.Collections.Generic;
    using System.Globalization;
    using System.Linq;
    using System.Text;

    public sealed class Ledger : IResult
    {
        public Ledger()
        {
            Entries = new List<decimal>();
        }

        public decimal Total
        {
            get
            {
                return Entries.Sum();
            }
        }

        private List<decimal> Entries { get; set; }

        public void Append(decimal value)
        {
            Entries.Add(value);
        }

        public override string ToString()
        {
            var buffer = new StringBuilder();
            foreach (var entry in Entries)
            {
                buffer.AppendLine(entry.ToString(CultureInfo.InvariantCulture));
            }

            return string.Concat(buffer.ToString(), "=", Total.ToString(CultureInfo.InvariantCulture));
        }
    }
}